﻿<%@ WebHandler Language="C#" Class="EquipmentMaintHandler" %>


using System;
using System.Web;
using BusinessRule.DTO;
using System.Web.SessionState;
using DatabaseAccess.DBUtility;
using System.Data.OracleClient;
using System.Data;
using System.Linq;
using System.Collections.Generic;
using System.Collections;
using Newtonsoft.Json;
using BusinessRule.Business;
using BusinessRule.IBusiness;
using BusinessRule.BusinessFactory;

//Description:设备维护处理程序
//Copyright (c) : 通力凯顿（北京）系统集成有限公司
//Writer:zhangrj
//create Date:2022-05-10
public class EquipmentMaintHandler : IHttpHandler, IRequiresSessionState
{
    CurrentUserInfo m_UserInfo;
    ResourceMaintBusiness resourceBusiness = new ResourceMaintBusiness();//设备类
    WorkShiftBusiness workShiftBusiness = new WorkShiftBusiness();//班次类
    uLMSCommonBusiness commonBusiness = new uLMSCommonBusiness();//通用类
    EmployeeMaintPageBusiness employeeMaintBusiness = new EmployeeMaintPageBusiness();//人员类
    public void ProcessRequest(HttpContext context)
    {
        try
        {
            var action = context.Request["action"].ToString();
            m_UserInfo = (CurrentUserInfo)context.Session["CurrentUserInfo"];
            switch (action)
            {
                case "InitPageData": //初始化页面数据
                    InitPageData(context);
                    break;
                case "GetResourceListByPage": //获取设备列表（分页）
                    GetResourceListByPage(context);
                    break;
                case "GetResourceMaintInfo": //获取设备保养信息
                    GetResourceMaintList(context);
                    break;
                case "GetResAndEmpInfo": //获取设备已绑定人员
                    GetResAndEmpInfo(context);
                    break;
                case "GetWorkCenter": //获取工区
                    GetWorkCenterList(context);
                    break;
                case "SaveResourceData": //保存设备信息（新增，更新）
                    SaveResourceData(context);
                    break;
                case "SaveBatchResourceData": //批量更新设备
                    SaveBatchResourceData(context);
                    break;
                case "SaveResourceMaintData": //保存设备保养信息
                    SaveResourceMaintData(context);
                    break;
                case "DeleResourceMaintData": //删除设备保养信息
                    DeleResourceMaintData(context);
                    break;
                case "GetEmployee": //查询用户信息
                    GetEmployee(context);
                    break;
                case "ResourceAddEmployee":
                    ResourceAddEmployee(context);//设备添加人员
                    break;
                case "ResourceRemoveEmployee":
                    ResourceRemoveEmployee(context);//设备移除人员
                    break;
                case "DealAbnormalEmp":
                    DealAbnormalEmp(context);//处理异常人员设备数据
                    break;
                case "saveResourceBatchParams"://设备组批参数维护
                    saveResourceBatchParams(context);
                    break;
                case "getCustomObjectData"://查询自定义产线属性信息(产线信息)
                    getCustomObjectData(context);
                    break;    
                default:
                    break;
            }
        }
        catch (Exception ex)
        {
            var result = new uMESProcessResult();
            result.Result = false;
            result.Message = ex.Message;
            context.Response.ContentType = "text/html";
            context.Response.Write(JsonConvert.SerializeObject(result));
        }
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
    /// <summary>
    /// 初始化页面数据
    /// </summary>
    /// <param name="context"></param>
    public void InitPageData(HttpContext context)
    {
        DataSet dtSet = new DataSet();
        //获取查询工区
        DataTable dtWorkCenter = commonBusiness.GetWorkCenterByFacoryID(m_UserInfo.FactoryID, false);
        dtWorkCenter.TableName = "dtWorkCenter";
        dtSet.Tables.Add(dtWorkCenter);
        //获取班次
        DataTable dtWorkShift = workShiftBusiness.GetWorkShiftList();
        dtWorkShift.TableName = "dtWorkShift";
        DataRow drws = dtWorkShift.NewRow();
        drws["WORKSHIFTID"] = "";
        drws["WORKSHIFTNAME"] = "无";
        dtWorkShift.Rows.InsertAt(drws, 0);//插入到第一行
        dtSet.Tables.Add(dtWorkShift);
        //获取工厂
        Dictionary<string, string> dic = new Dictionary<string, string>();
        //dic.Add("FactoryGone", "");
        DataTable dtFactory = commonBusiness.GetFactory(dic);
        dtFactory.TableName = "dtFactory";
        dtSet.Tables.Add(dtFactory);
        //获取设备型号
        DataTable dtResourceFamily = resourceBusiness.GetResourceFamily();
        dtResourceFamily.TableName = "dtResourceFamily";
        dtSet.Tables.Add(dtResourceFamily);
        //获取日历
        DataTable dtMakeCalendar = resourceBusiness.GetMakeCalendarInfo();
        dtMakeCalendar.TableName = "dtMakeCalendar";
        DataRow drmc = dtMakeCalendar.NewRow();
        drmc["MAKECALENDARID"] = "";
        drmc["MAKECALENDARNAME"] = "无";
        dtMakeCalendar.Rows.InsertAt(drmc, 0);//插入到第一行
        dtSet.Tables.Add(dtMakeCalendar);
        context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { DBDataSet = dtSet }));
    }
    /// <summary>
    /// 获取工区（通过工厂）
    /// </summary>
    /// <param name="context"></param>
    public void GetWorkCenterList(HttpContext context)
    {
        string factoryId = context.Request["factoryId"].ToString();
        //获取工区
        DataTable dtWorkCenter = commonBusiness.GetWorkCenterByFacoryID(factoryId, false);
        context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Result = true, DBTable = dtWorkCenter }));
    }

    /// <summary>
    /// 获取设备列表（分页）
    /// </summary>
    /// <param name="context"></param>
    public void GetResourceListByPage(HttpContext context)
    {
        string resourceName = context.Request["resourceName"].ToString();
        string description = context.Request["description"].ToString();
        string resourceFamilyname = context.Request["resourceFamilyname"].ToString();
        string workcentername = context.Request["workcentername"].ToString();
        string teamName = context.Request["teamName"].ToString();
        string isinfinite = context.Request["isinfinite"].ToString();
        string pageSize = context.Request["pageSize"].ToString();
        string pageNumber = context.Request["pageNumber"].ToString();
        
        Dictionary<string, string> dic = new Dictionary<string, string>();
        dic.Add("resourcename", resourceName);//设备编码
        dic.Add("description", description);//设备名称
        dic.Add("resourcefamilyname", resourceFamilyname);//设备型号
        dic.Add("workcentername", workcentername);//工区
        dic.Add("teamname", teamName);//班组
        dic.Add("factoryid", m_UserInfo.FactoryID);//查询本分厂
        dic.Add("isinfinite", isinfinite);//有限能力设备是否已维护
        dic.Add("isNotFactory", context.Request["isNotFactory"].ToString());//是否查询无分厂设备（配合分厂一起查询）
        dic.Add("PageSize", pageSize);
        dic.Add("PageIndex", pageNumber);
        uMESProcessResult result = resourceBusiness.GetResourceInfo(dic);
        context.Response.Write(JsonConvert.SerializeObject(result));
    }
    /// <summary>
    /// 获取设备保养信息
    /// </summary>
    /// <param name="context"></param>
    public void GetResourceMaintList(HttpContext context)
    {
        string resourceId = context.Request["resourceId"].ToString();
        string pageSize = context.Request["pageSize"].ToString();
        string pageNumber = context.Request["pageNumber"].ToString();
        Dictionary<string, string> dic = new Dictionary<string, string>();
        dic.Add("resourceid", resourceId);//设备ID
        dic.Add("PageSize", pageSize);
        dic.Add("PageIndex", pageNumber);
        uMESProcessResult result = resourceBusiness.GetResourceMaintList(dic);
        context.Response.Write(JsonConvert.SerializeObject(result));
    }
    /// <summary>
    /// 获取设备人员信息
    /// </summary>
    /// <param name="context"></param>
    public void GetResAndEmpInfo(HttpContext context)
    {
        string resourceId = context.Request["resourceId"].ToString();
        string pageSize = context.Request["pageSize"].ToString();
        string pageNumber = context.Request["pageNumber"].ToString();
        Dictionary<string, string> dic = new Dictionary<string, string>();
        dic.Add("ResourceID", resourceId);//设备ID
        dic.Add("PageSize", pageSize);
        dic.Add("PageIndex", pageNumber);
        uMESProcessResult result = resourceBusiness.GetResAndEmpInfo(dic);
        context.Response.Write(JsonConvert.SerializeObject(result));
    }
    /// <summary>
    /// 保存设备信息（新增，更新）
    /// </summary>
    /// <param name="context"></param>
    public void SaveResourceData(HttpContext context)
    {
        DataTable dtMain = JsonConvert.DeserializeObject<DataTable>(context.Request["params"].ToString());
        Dictionary<string, string> dic = new Dictionary<string, string>();
        if (dtMain.Rows.Count == 0)
        {
            context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Result = false, Message = "没有需要保存的数据" }));
            return;
        }
        string type = context.Request["type"].ToString();
        DataRow dr = dtMain.Rows[0];
        dic.Add("resourcename", dr["resourceNum"].ToString());//设备编码
        dic.Add("description", dr["resourceName"].ToString());//设备名称
        dic.Add("notes", dr["notes"].ToString());//备注
        dic.Add("resourcefamily", dr["resourceFamily"].ToString());//设备类型
        dic.Add("factoryname", dr["factory"].ToString());//分厂
        dic.Add("workcentername", dr["workCenter"].ToString());//工区
        dic.Add("teamname", dr["team"].ToString());//班组
        dic.Add("isuse", dr["isUse"].ToString());//是否启用
        dic.Add("productline", dr["productline"].ToString());//设备产线属性 add by longb 2024-04-01
        dic.Add("isVirtual", dr["isVirtual"].ToString());//是否虚拟设备 add by zhangrj 20250711
        dic.Add("userName", m_UserInfo.APIUserName.ToString());//
        dic.Add("passWord", m_UserInfo.APIPassword.ToString());//
        uMESProcessResult result = new uMESProcessResult();
        string msg = "";
        result.Result = resourceBusiness.ResourceMaint(type, dic, ref msg);
        result.Message = result.Result ? "操作成功" : "操作失败，原因：" + msg;
        context.Response.Write(JsonConvert.SerializeObject(result));
    }
    /// <summary>
    /// 批量删除、更新设备信息（更新只更新班次和日历）
    /// </summary>
    /// <param name="context"></param>
    public void SaveBatchResourceData(HttpContext context)
    {
        DataTable dtMain = JsonConvert.DeserializeObject<DataTable>(context.Request["params"].ToString());
        Dictionary<string, string> dic = new Dictionary<string, string>();
        if (dtMain.Rows.Count == 0)
        {
            context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Result = false, Message = "没有选择设备" }));
            return;
        }
        string type = context.Request["type"].ToString();
        string operType = "删除";
        if (type == "update")//如果是更新
        {
            string workShiftId = context.Request["workShiftId"].ToString();
            string makeCalendar = context.Request["makeCalendar"].ToString();
            string isBottLeneck = context.Request["isBottLeneck"].ToString();
            string priorityNum = context.Request["priorityNum"].ToString();
            string nextMakeCalendar = context.Request["nextMakeCalendar"].ToString();//add by longb 2023-03-28
            string isinfinite = context.Request["isinfinite"].ToString();//add by longb 2023-08-23
            dic.Add("workshiftid", workShiftId);//班次
            dic.Add("makecalendar", makeCalendar);//日历
            dic.Add("nextmakecalendar", nextMakeCalendar);//add by longb 2023-03-28
            dic.Add("isbottleneck", isBottLeneck);//瓶颈设备
            dic.Add("prioritynum", priorityNum);//优先级
            dic.Add("isinfinite", isinfinite);//是否无限能力设备
            operType = "更新";
        }
        dic.Add("resourcename", "");
        dic.Add("userName", m_UserInfo.APIUserName.ToString());//
        dic.Add("passWord", m_UserInfo.APIPassword.ToString());//
        uMESProcessResult result = new uMESProcessResult();
        result.Message = "设备";
        foreach (DataRow item in dtMain.Rows)
        {
            dic["resourcename"] = item["RESOURCENAME"].ToString();//设备编码
            string operMsg = "";
            result.Result = resourceBusiness.ResourceMaint(type, dic, ref operMsg);
            if (!result.Result)
            {
                if (result.Message != "设备")
                {
                    result.Message += operType + "成功。";
                }
                result.Message += "[" + item["RESOURCENAME"].ToString() + "]" + operType + "失败，原因：" + operMsg;
                break;
            }
            result.Message += "[" + item["RESOURCENAME"].ToString() + "]";
        }
        result.Message += result.Result ? operType + "成功。" : "";
        context.Response.Write(JsonConvert.SerializeObject(result));
    }
    /// <summary>
    /// 保存设备保养信息
    /// </summary>
    /// <param name="context"></param>
    public void SaveResourceMaintData(HttpContext context)
    {
        Dictionary<string, string> dic = new Dictionary<string, string>();
        string startTime = context.Request["startTime"].ToString();
        string endTime = context.Request["endTime"].ToString();
        string resourceId = context.Request["resourceId"].ToString();
        dic.Add("upkeepstartdate", startTime);//开始日期
        dic.Add("upkeependdate", endTime);//结束日期
        dic.Add("resourceid", resourceId);//设备ID
        uMESProcessResult result = new uMESProcessResult();
        result = resourceBusiness.InsertResourceUpKeepInfo(dic);
        context.Response.Write(JsonConvert.SerializeObject(result));
    }
    /// <summary>
    /// 删除设备保养信息
    /// </summary>
    /// <param name="context"></param>
    public void DeleResourceMaintData(HttpContext context)
    {
        DataTable dtMain = JsonConvert.DeserializeObject<DataTable>(context.Request["params"].ToString());
        Dictionary<string, string> dic = new Dictionary<string, string>();
        if (dtMain.Rows.Count == 0)
        {
            context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Result = false, Message = "没有选择需要删除的数据" }));
            return;
        }
        uMESProcessResult result = resourceBusiness.DeleteResourceUpKeepInfoBatch(dtMain);
        context.Response.Write(JsonConvert.SerializeObject(result));
    }

    //查询用户
    void GetEmployee(HttpContext context)
    {
        string empinfo = context.Request["Name"].ToString();
        uMESProcessResult result = resourceBusiness.GetEmployee(empinfo);
        context.Response.Write(JsonConvert.SerializeObject(result));
    }

    //设备添加人员
    void ResourceAddEmployee(HttpContext context)
    {
        if (m_UserInfo == null)
        {
            context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Result = false, Message = "当前未登录", DBTable = null }));
        }

        string employeeid = context.Request.Form["employeeid"].ToString();
        string resourcename = context.Request.Form["resourcename"].ToString();
        string resourceid = context.Request.Form["resourceid"].ToString();
        string msg = "";

        string sql = string.Format("SELECT e.employeeid,e.employeename,e.fullname FROM employee e WHERE e.employeeid='{0}'", employeeid);
        DataTable dtEmployeeInfo = DatabaseHelper.Query_ReturnDatTable(sql);

        //resourceCount：人员当前已绑定设备数
        sql = @"SELECT e.employeeid,e.employeename,e.fullname,rd.resourcename,rd.resourceid
                FROM employeeresourcelist er
                LEFT JOIN resourcedef rd ON rd.resourceid = er.resourcelistid
                LEFT JOIN employee e ON e.employeeid = er.employeeid
                WHERE er.employeeid = '{0}'";
        sql = string.Format(sql, employeeid);
        DataTable dtResource = DatabaseHelper.Query_ReturnDatTable(sql);
        int resourceCount = dtResource.Rows.Count;

        Dictionary<string, string> para = new Dictionary<string, string>();
        para["employeename"] = dtEmployeeInfo.Rows[0]["employeename"].ToString();
        para["resourceCount"] = resourceCount.ToString();
        para["userName"] = m_UserInfo.APIUserName.ToString();
        para["passWord"] = m_UserInfo.APIPassword.ToString();

        //校验设备是否已绑定该人员
        sql = @"SELECT e.employeeid,e.employeename,e.fullname,rd.resourcename,rd.resourceid
                FROM employeeresourcelist er
                LEFT JOIN resourcedef rd ON rd.resourceid = er.resourcelistid
                LEFT JOIN employee e ON e.employeeid = er.employeeid
                WHERE er.employeeid = '{0}' AND er.resourcelistid = '{1}'";
        sql = string.Format(sql, employeeid, resourceid);

        if (DatabaseHelper.Query_ReturnDatTable(sql).Rows.Count == 0)
        {
            DataRow drWillBeAddedResource = dtResource.NewRow();
            drWillBeAddedResource["resourceid"] = resourceid;
            drWillBeAddedResource["resourcename"] = resourcename;
            dtResource.Rows.Add(drWillBeAddedResource);

            bool result = employeeMaintBusiness.SaveEmployeeResource(para, dtResource, ref msg);
            context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Result = result, Message = msg, DBTable = null }));
        }
        else
        {
            string fullname = dtEmployeeInfo.Rows[0]["fullname"].ToString();
            msg = string.Format("【{0}({1})】已绑定设备【{2}】，不能重复添加!", para["employeename"], fullname, resourcename);
            context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Result = false, Message = msg, DBTable = null }));
        }
    }

    //设备移除人员
    void ResourceRemoveEmployee(HttpContext context)
    {
        if (m_UserInfo == null)
        {
            context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Result = false, Message = "当前未登录", DBTable = null }));
        }

        DataTable dtEmployee = JsonConvert.DeserializeObject<DataTable>(context.Request["employeeList"].ToString());
        string resourcename = context.Request.Form["resourcename"].ToString();
        string resourceid = context.Request.Form["resourceid"].ToString();

        foreach (DataRow dr in dtEmployee.Rows)
        {
            string employeeid = dr["EMPLOYEEID"].ToString();
            string sql = string.Format("SELECT e.employeeid,e.employeename,e.fullname FROM employee e WHERE e.employeeid='{0}'", employeeid);
            DataTable dtEmployeeInfo = DatabaseHelper.Query_ReturnDatTable(sql);

            //resourceCount：移除所选设备之前，人员当前绑定的设备数
            sql = @"SELECT e.employeeid,e.employeename,e.fullname,rd.resourcename,rd.resourceid
                    FROM employeeresourcelist er
                    LEFT JOIN resourcedef rd ON rd.resourceid = er.resourcelistid
                    LEFT JOIN employee e ON e.employeeid = er.employeeid
                    WHERE er.employeeid = '{0}'";
            sql = string.Format(sql, employeeid);
            int resourceCount = DatabaseHelper.Query_ReturnDatTable(sql).Rows.Count;

            sql = @"SELECT e.employeeid,e.employeename,e.fullname,rd.resourcename,rd.resourceid
                    FROM employeeresourcelist er
                    LEFT JOIN resourcedef rd ON rd.resourceid = er.resourcelistid
                    LEFT JOIN employee e ON e.employeeid = er.employeeid
                    WHERE er.employeeid = '{0}' AND er.resourcelistid <> '{1}'";
            sql = string.Format(sql, employeeid, resourceid);

            //dtResource：移除所选设备后，人员将要绑定的设备清单
            DataTable dtResource = DatabaseHelper.Query_ReturnDatTable(sql);

            Dictionary<string, string> para = new Dictionary<string, string>();
            para["employeename"] = dtEmployeeInfo.Rows[0]["employeename"].ToString();
            para["resourceCount"] = resourceCount.ToString();
            para["userName"] = m_UserInfo.APIUserName.ToString();
            para["passWord"] = m_UserInfo.APIPassword.ToString();

            string msg = "";
            bool result = employeeMaintBusiness.SaveEmployeeResource(para, dtResource, ref msg);
        }

        context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Result = true, Message = "", DBTable = null }));
    }

    /// <summary>
    /// 处理异常的人员设备
    /// </summary>
    /// <param name="context"></param>
    private void DealAbnormalEmp(HttpContext context)
    {
        ArrayList list = new ArrayList();
        string employeeID = context.Request.Form["employeeid"].ToString();
        string sql = string.Format(@"SELECT er.employeeid,rd.resourceid,er.sequence,er.fieldid
                                   FROM employeeresourcelist er
                                   LEFT JOIN resourcedef rd ON rd.resourceid = er.resourcelistid
                                   WHERE er.employeeid = '{0}'
                                   ORDER BY er.sequence", employeeID);
        DataTable dtEmpRes = DatabaseHelper.Query_ReturnDatTable(sql);
        DataRow[] drs = dtEmpRes.AsEnumerable().Where(p => string.IsNullOrWhiteSpace(p["resourceid"].ToString())).ToArray();//查询设备为空的情况
        if (drs.Length > 0) //如果存在为空，则删除为空的数据，并重新排序
        {
            foreach (DataRow item in drs)
            {
                sql = string.Format("DELETE employeeresourcelist er WHERE er.employeeid = '{0}' AND er.sequence = {1} AND er.fieldid = {2}", employeeID, int.Parse(item["sequence"].ToString()), int.Parse(item["fieldid"].ToString()));
                list.Add(sql);
            }
            DatabaseHelper.ExecuteSqlTran(list);
            //删除完后再查一次所有的数据
            sql = string.Format(@"SELECT er.sequence,er.fieldid FROM employeeresourcelist er WHERE er.employeeid = '{0}' ORDER BY er.sequence", employeeID);
            dtEmpRes = DatabaseHelper.Query_ReturnDatTable(sql);
            list.Clear();
        }
        //检查顺序号是否连续（从1开始连续）
        for (int i = 0; i < dtEmpRes.Rows.Count; i++)
        {
            int sequence = int.Parse(dtEmpRes.Rows[i]["sequence"].ToString());
            int fieldid = int.Parse(dtEmpRes.Rows[i]["fieldid"].ToString());
            if (sequence != (i + 1))
            {
                sql = string.Format("UPDATE employeeresourcelist er SET er.sequence = {0} WHERE er.employeeid = '{1}' AND er.sequence = {2} AND er.fieldid = {3}", (i + 1), employeeID, sequence, fieldid);
                list.Add(sql);
            }
        }
        if (list.Count > 0)
        {
            DatabaseHelper.ExecuteSqlTran(list);
        }
        context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Result = true, Message = "处理完成" }));
    }
    /// <summary>
    /// 设备组批参数维护 add by longb 2024-07-24
    /// </summary>
    /// <param name="context"></param>
    public void saveResourceBatchParams(HttpContext context) 
    {
        string IsCombineBatch = context.Request.Form["IsCombineBatch"].ToString();
        string UpperLimit = context.Request.Form["UpperLimit"].ToString();
        string CombineRule = context.Request.Form["CombineRule"].ToString();
        var dt =JsonConvert.DeserializeObject<DataTable>(context.Request.Form["params"].ToString());

        var arrList = new ArrayList();
        foreach(DataRow row in dt.Rows)
        {
            arrList.Add(string.Format("update RESOURCEDEF set IsCombineBatch='{0}', UpperLimit='{1}',CombineRule='{2}' where RESOURCEID='{3}'", IsCombineBatch, UpperLimit, CombineRule, row["RESOURCEID"]));
        }
        
       var result=  new uMESProcessResult();
       result.Result = DatabaseHelper.ExecuteSqlListTran(arrList);
       result.Message = result.Result ? "保存成功" : "保存失败";
       context.Response.Write(JsonConvert.SerializeObject(result));
    }
    /// <summary>
    /// 查询自定义产线属性信息
    /// </summary>
    /// <param name="context"></param>
    private void getCustomObjectData(HttpContext context)
    {
        var selectSQL = @"SELECT distinct c.customobjectname,c.customobjectid customobjectitemsid,c.customobjectname customobjectitemsname 
                    from customobject c 
                    left join customobjectitems item on item.customobjectid =c.customobjectid
                    where c.customobjectname like '%CX-%' 
                    and c.isuse=0 and item.isuse =0 and item.factoryid ='{0}'";
        DataTable dt = DatabaseHelper.Query_ReturnDatTable(string.Format(selectSQL, m_UserInfo.FactoryID));
        DataRow drws = dt.NewRow();
        drws["CUSTOMOBJECTITEMSID"] = "";
        drws["CUSTOMOBJECTITEMSNAME"] = "\u3000";
        dt.Rows.Add(drws);//插入到第一行
        context.Response.Write(JsonConvert.SerializeObject(dt));
    }
    
}